﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TimeWork
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DdlLevel2.Visible = false;
                DdlLevel3.Visible = false;
                BindDdlLevel(DdlLevel1,"--- Chọn mã cấp 1 ---",0);
            }
        }

        private void BindDdlLevel(DropDownList ddl, string itemFirst, int parentId)
        {
            ddl.DataSource = TimeSystem.GetWork(parentId);
            ddl.DataTextField = "WorkName";
            ddl.DataValueField = "Id";

            ddl.DataBind();
            // Them gia tri tuy chon
            ddl.Items.Insert(0, new ListItem(itemFirst, "0"));
            // Thiet lap chon gia tri ban dau
            ddl.SelectedValue = "0";
        }

        protected void DdlLevel1_SelectedIndexChanged(object sender, EventArgs e)
        {
            DdlLevel3.Visible = false;
            string itemSelected = DdlLevel1.SelectedValue;
            if (itemSelected.Equals("0"))
            {
                DdlLevel2.Visible = false;   
            }
            else
            {
                DdlLevel2.Visible = true;
                BindDdlLevel(DdlLevel2,"--- Chọn mã cấp 2 ---", Int32.Parse(itemSelected));
            }
        }

        protected void DdlLevel2_SelectedIndexChanged(object sender, EventArgs e)
        {
            string itemSelected = DdlLevel2.SelectedValue;
            if (itemSelected.Equals("0"))
            {
                DdlLevel3.Visible = false;
            }
            else
            {
                DdlLevel3.Visible = true;
                BindDdlLevel(DdlLevel3, "--- Chọn mã cấp 3 ---", Int32.Parse(itemSelected));
            }
        }

    }
}